package com.yet.kotlinapp.modules.login

import android.os.Bundle
import android.os.PersistableBundle
import com.blankj.utilcode.util.ToastUtils
import com.qmuiteam.qmui.arch.QMUIActivity
import com.qmuiteam.qmui.arch.QMUIFragmentActivity
import com.yet.kotlinapp.databinding.ActivityMainBinding
import com.yet.kotlinapp.databinding.LoginActivityBinding
import com.yet.kotlinapp.entity.LoginResponseInfo
import com.yet.kotlinapp.modules.login.inter.LoginView
import java.util.zip.Inflater

/**
 *
 * @ProjectName: Kotlin app
 * @Package: com.yet.kotlinapp.modules.login
 * @ClassName: LoginActivity
 * @Description: java类作用描述
 * @Author: liys
 * @CreateDate: 2021/8/27 11:27
 * @UpdateUser: 更新者
 * @UpdateDate: 2021/8/27 11:27
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
class LoginActivity : QMUIFragmentActivity(),LoginView {

    lateinit var loginActivityBinding:LoginActivityBinding
    lateinit var loginPresenterImp:LoginPresenterImp

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        loginActivityBinding = LoginActivityBinding.inflate(layoutInflater)
        var rootView = loginActivityBinding.root
        setContentView(rootView)
        loginPresenterImp= LoginPresenterImp(this)
        loginActivityBinding.btLogin.setOnClickListener {
            val user:String=loginActivityBinding.edUser.text.toString()
            val pw : String=loginActivityBinding.edPw.text.toString()
            loginPresenterImp.loginaction(this,user,pw);
        }
        loginActivityBinding.btRegister.setOnClickListener {
            loginPresenterImp.toRegist(this)
        }
    }

    override fun loginSuccess(loginBean: LoginResponseInfo?) {
       if (loginBean?.data == null){
           ToastUtils.showLong(loginBean?.errorMsg)
       }else{
           ToastUtils.showLong("登录成功")
           loginPresenterImp.toHome(this,loginBean.data.publicName)
       }
    }

    override fun loginFialure(erroeMsg: String?) {
        ToastUtils.showLong(erroeMsg);
    }
}